#include<iostream>
using namespace std;

int main()
{
    int n = 0;
    cin >> n;
    int a = 0, b = 1, c = 1;
    while(c<n)
    {
        a = b;
        b = c;
        c = a+b;
    }
    cout << min(n-b, c-n) << endl;
    return 0;
}